package com.onefinger.manager.mocks
{
	import com.onefinger.manager.vos.Category;
	import com.onefinger.manager.vos.Subcategory;
	
	import mx.collections.ArrayCollection;

	public class SubCategoryMockService
	{
		
		private var _list:ArrayCollection = new ArrayCollection();
		
		public function SubCategoryMockService()
		{
			var categoryService:CategoryMockService = new CategoryMockService();
	/*		var wineCategory:Category = new Category();
			wineCategory.id = 1;
			wineCategory.name = "Vinos";
			wineCategory.showOrder = 1;
			wineCategory.icon = "wines.jpg";*/
			var wineSubcategory:Subcategory=new Subcategory();
			wineSubcategory.icon= "wines.jpg";
			wineSubcategory.category=categoryService.list().getItemAt(0) as Category;
			wineSubcategory.name ="Malbec";
			wineSubcategory.shortDescription="uvas de malbec";
			wineSubcategory.showOrder=1;
				
			_list.addItem( wineSubcategory );
		}
		
		
		public function list():ArrayCollection
		{
			return _list;
		}
		
		public function save( subcategory:Subcategory ):Boolean
		{
			var index:int = _list.getItemIndex( subcategory );
			if( index != -1 )
			{
				return true;
			} else {
				_list.addItem(subcategory);
				return true;
			}
		}
		public function update( subcategory:Subcategory ):Boolean
		{
			var index:int = _list.getItemIndex( subcategory );
			if( index != -1 )
			{
				_list.list.itemUpdated(subcategory);
				return true;
			} else {
				return true;
			}
		}
		
		public function remove(subcategory:Subcategory):Boolean
		{
			var index:int = _list.getItemIndex( subcategory );
			if( index == -1 )
			{
				return false;
			} else {
				_list.removeItemAt( index );
				return true;
			}
		}
		public function updateSubcategories(category:Category):ArrayCollection
		{
			var filterList:ArrayCollection = new ArrayCollection();
			for (var i:int = 0; i < _list.length; i++) 
			{
				var aux:Subcategory = _list[i] as Subcategory;
				if (aux.category.name == category.name){
					filterList.addItem(aux);
				}
			}
			return filterList;
		}
	}
}